package  com.pcbly.web.business.news;

/**
* @author carl.song
* Copyright (c) 2010 Lightsoft, International.
* All rights reserved.
*
*/

import java.util.HashMap;
import java.util.List;

import com.pcbly.web.persistence.news.NewsConfigDao;
import com.pcbly.web.persistence.table.ColumnDao;
import com.pcbly.web.bean.news.NewsConfigBean;
import com.pcbly.web.bean.table.ColumnBean;
import com.pcbly.web.business.BaseServiceImp;
import com.pcbly.web.components.hibernate.support.Page;
import com.pcbly.web.components.form.AbstractAnalyseCommonDataExt;
import com.pcbly.web.components.form.AnalyseCommonDataExtCreate;
import com.pcbly.web.components.form.AnalyseCommonDataExtEdit;
import com.pcbly.web.components.form.AnalyseCommonDataExtView;

 
public class NewsConfigServiceImp extends BaseServiceImp<NewsConfigBean> implements NewsConfigService {
	 public NewsConfigServiceImp() {
		super();
		// TODO Auto-generated constructor stub
	}
	private NewsConfigDao newsConfigDao;
	
	private ColumnDao columnDao;

	public void setColumnDao(ColumnDao columnDao) {
		this.columnDao = columnDao;
	}
	
	public void setNewsConfigDao(NewsConfigDao newsConfigDao) {
		this.newsConfigDao = newsConfigDao;
	}
	
	@Override
	public NewsConfigBean getNewsConfigBeanById(String id) throws Exception {
		// TODO Auto-generated method stub
		return newsConfigDao.get(NewsConfigBean.class,id);
	}
	
	@Override
	public void removeNewsConfigBeanById(String id) throws Exception{
		newsConfigDao.removeNewsConfigBeanById(id);
	}
	
	@Override
	public void removeNewsConfigBeanByIds(String ids) throws Exception{
		newsConfigDao.removeNewsConfigBeanByIds(ids);
	}
	
	
	@Override
	public NewsConfigBean saveNewsConfigBean(NewsConfigBean news) throws Exception{
		return newsConfigDao.saveNewsConfigBean(news);
	}
	
	@Override
	public NewsConfigBean updateNewsConfigBean(NewsConfigBean news) throws Exception{
		newsConfigDao.saveObject( news);
		return news;
	}
	public Page<NewsConfigBean>  findNewsConfigBeanByCond(NewsConfigBean bean,
			Page<NewsConfigBean> page, String orderByName, boolean asc)
			throws Exception{
		return newsConfigDao.findNewsConfigBeanByCond(
				bean, page, orderByName, asc);
	}
	
	@Override
	public String findNewsConfigBeanExtCreate(String tableName) throws Exception {
		// TODO Auto-generated method stub
		List<ColumnBean> columnList = columnDao
				.findColumnBeansByTableName(tableName);
		AbstractAnalyseCommonDataExt common = new AnalyseCommonDataExtCreate();
		common.setColumnList(columnList);
		return common.execute().toString();
	}

	@Override
	public String findNewsConfigBeanExtEdit(String tableName, String id)
			throws Exception {
		// TODO Auto-generated method stub
		List<HashMap<String, String>> dataList = newsConfigDao
				.findCommnonDataBeanExt(tableName, id);
		List<ColumnBean> columnList = columnDao
				.findColumnBeansByTableName(tableName);
		AbstractAnalyseCommonDataExt common = new AnalyseCommonDataExtEdit();
		common.setDataList(dataList);
		common.setColumnList(columnList);
		return common.execute().toString();
	}

	@Override
	public String findNewsConfigBeanExtView(String tableName, String id)
			throws Exception {
		// TODO Auto-generated method stub
		List<HashMap<String, String>> dataList = newsConfigDao
				.findCommnonDataBeanExt(tableName, id);
		List<ColumnBean> columnList = columnDao
				.findColumnBeansByTableName(tableName);
		AbstractAnalyseCommonDataExt common = new AnalyseCommonDataExtView();
		common.setDataList(dataList);
		common.setColumnList(columnList);
		return common.execute().toString();
	}

	@Override
	public void saveNewsConfigBeanExt(String sql) throws Exception {
		// TODO Auto-generated method stub
		newsConfigDao.saveCommnonDataBeanExt(sql);
	}

	@Override
	public boolean getHasNewsConfigBeanExtData(String tableName, String id)
			throws Exception {
		// TODO Auto-generated method stub
		return newsConfigDao.getHasCommnonDataBeanExt(tableName, id);
	}
}
